package com.industrial.app.excel.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.Map;

public class ReadSpecifyRowListener extends AnalysisEventListener<Map> {


    private Integer preReadRowIndex = 0;


    public ReadSpecifyRowListener(Integer preReadRowIndex) {
        this.preReadRowIndex = preReadRowIndex;
    }

    private Map data;

    /**
     * When analysis one row trigger invoke function.
     *
     * @param data    one row value. Is is same as {@link AnalysisContext#readRowHolder()}
     * @param context analysis context
     */
    @Override
    public void invoke(Map data, AnalysisContext context) {
        Integer rowIndex = context.readRowHolder().getRowIndex();
        if(!rowIndex.equals(preReadRowIndex)){
            return;
        }
        this.data = data;
    }

    public Map getData(){
        return data;
    }

    /**
     * if have something to do after all analysis
     *
     * @param context
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {

    }
}
